<template>
  <div class="bread" v-if="childName">
    <el-breadcrumb separator="/">
      <el-breadcrumb-item>后台首页</el-breadcrumb-item>
      <el-breadcrumb-item>{{ childName }}</el-breadcrumb-item>
    </el-breadcrumb>
  </div>
</template>

<script>
export default {
  name: "Breadcrumb",
  data() {
    return {
      childName: "",
    };
  },
  methods: {
    getRoute() {
      const path = this.$route.path.replace("/", "");
      for (const parent of this.$store.getters.tree) {
        const child = parent.child.find((c) => c.frontpath === path);
        if (child) {
          this.childName = child.name==='后台首页'?'':child.name;
          break;
        }
      }
    },
  },
  watch: {
    /**
     * 监听当前的路由信息
     */
    $route: {
      immediate: true,
      handler() {
        this.getRoute();
      },
    },
  },
};
</script>

<style lang="scss" scoped>
.bread {
  padding: 20px;
  border-bottom: 1px solid #dee2e6;
}
</style>